<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Diner - Salt Meal Backend</title>
  <script th:src="@{../js/onesalt.js}" src="../static/js/onesalt.js"></script>
  <link th:if="false" href="../static/css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <div class="panel" th:with="isEdit=${type.equals('add') || type.equals('edit')}">
    <form class="form-horizontal" id="form" onSubmit="submitSearch();return false;" th:type="${type}">
      <input th:if="${type} != 'add'" type="hidden" name="userId" th:value="${user.userId}" />
      <input th:if="${type} != 'add'" type="hidden" name="sn" th:value="${user.sn}" />
      <div th:if="${type} != 'add'" class="form-group">
        <label class="col-sm-2 control-label">厨师ID</label>
        <div class="col-sm-10">
          <p class="form-control-static" th:text="${user.sn}">CHN001</p>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">姓名</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.name}">张三</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="name" th:value="${user.name}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">职业</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.profession}">张三</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="profession" th:value="${user.profession}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">所在城市</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.city}">上海</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="city" th:value="${user.city}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">餐厅名字</label>
        <div class="col-sm-10">
          <a th:if="!${isEdit}" class="form-control-static" href="#" th:href="@{'./kitchens?cookId=' + ${user.cook.cookId}}" th:text="${user.cook.kitchen != null ? user.cook.kitchen.name : ''}">餐厅1</a>
          <input th:if="${isEdit}" type="text" class="form-control" name="cook.kitchen.name" th:value="${user.cook.kitchen != null ? user.cook.kitchen.name : ''}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">联系电话</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.tel}">021-88888888</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="tel" th:value="${user.tel}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">手机号</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.mobile}">13800000000</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="mobile" th:value="${user.mobile}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">擅长厨艺</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.cook.skills}">13800000000</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="cook.skills" th:value="${user.cook.skills}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">就餐人数</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.cook.diningCount}">test1@163.com</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="cook.diningCount" th:value="${user.cook.diningCount}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">性别</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.sex}">test1@163.com</p>
          <!-- Split button -->
          <div class="btn-group" th:if="${isEdit}">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
              <span id="sex-span" th:text="${user.sex}">无</span>
              <span class="caret"></span>
            </button>
            <input type="hidden" name="sex" value="" th:value="${user.sex}" />
            <ul class="dropdown-menu" role="menu">
              <li>
                <a class="sex-link" href="#">男</a>
                <a class="sex-link" href="#">女</a>
                <a class="sex-link" href="#">无</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">年龄</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.age}">test1@163.com</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="age" th:value="${user.age}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">Email</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.email}">test1@163.com</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="email" th:value="${user.email}" value="" />
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">社交帐号</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.socialAccount}">test1@163.com</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="socialAccount" th:value="${user.socialAccount}" value="" />
        </div>
      </div>
      <div class="form-group" th:if="!${isEdit}">
        <label class="col-sm-2 control-label">注册时间</label>
        <div class="col-sm-10">
          <p class="form-control-static" th:text="${user.registerTime != null ? #calendars.format(user.registerTime, 'yy-MM-dd hh:mm') : ''}">2012-03-18 18:00</p>
        </div>
      </div>
      <div class="form-group" th:if="!${isEdit}">
        <label class="col-sm-2 control-label">申请时间</label>
        <div class="col-sm-10">
          <p class="form-control-static" th:text="${user.cook.applyTime != null ? #calendars.format(user.cook.applyTime, 'yy-MM-dd hh:mm') : ''}">2012-03-18 18:00</p>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">备注</label>
        <div class="col-sm-10">
          <p th:if="!${isEdit}" class="form-control-static" th:text="${user.notes}">test1@163.com</p>
          <input th:if="${isEdit}" type="text" class="form-control" name="notes" th:value="${user.notes}" value="" />
        </div>
      </div>
      <div class="form-group">
        <div class="col-sm-2 col-sm-offset-5">
          <input type="submit" class="form-control" th:value="${isEdit} ? '保存' : '编辑'" value="提交" />
        </div>
      </div>
    </form>
    <script>
    $(function() {
      $(".sex-link").click(function(e) {
        var sex = $(this).text();
        $("#sex-span").text(sex);
        $("#form input[name='sex']").first().attr("value", sex);
      });
    });
    function submitSearch() {
      var type = $("#form").attr("type");
      var cookId = $("#form input[name='sn']").first().attr("value");
      if(type == 'add') {
        loadContent("./cooks", $("#form").serializeArray());
      } else if (type == 'edit') {
        loadContent("./cooks/" + cookId, $("#form").serializeArray());
      } else {
        loadContent("./cooks/" + cookId + "?edit=true");
      }
    }
    </script>
  </div>
</body>
</html>